package com.example.tnot.login.fragmentui;

import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import com.example.tnot.R;
import com.example.tnot.login.fragmentui.IdentitySelectFragmentDirections;

public class IdentitySelectFragment extends Fragment {


    Button btn_login_teacher;
    Button btn_login_student;
    boolean teacher_flag;
    boolean student_flag;

    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";
    private String mParam1;
    private String mParam2;

    public IdentitySelectFragment() {
    }
    public static IdentitySelectFragment newInstance(String param1, String param2) {
        IdentitySelectFragment fragment = new IdentitySelectFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        args.putString(ARG_PARAM2, param2);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View v =  inflater.inflate(R.layout.fragment_identity_select, container, false);

//寻找教室入口和学生入口按钮
        btn_login_student = v.findViewById(R.id.btn_login_student);
        btn_login_teacher = v.findViewById(R.id.btn_login_teacher);

//教师入口
        btn_login_teacher.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                teacher_flag = true;
                student_flag = false;
                IdentitySelectFragmentDirections.ActionIdentitySelectFragmentToLoginFragment action = IdentitySelectFragmentDirections.actionIdentitySelectFragmentToLoginFragment(teacher_flag);
                NavController navController = Navigation.findNavController(v);
                navController.navigate(action);
            }
        });
//学生入口
        btn_login_student.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                teacher_flag = false;
                student_flag = true;
                IdentitySelectFragmentDirections.ActionIdentitySelectFragmentToLoginFragment action = IdentitySelectFragmentDirections.actionIdentitySelectFragmentToLoginFragment(teacher_flag);
                NavController navController = Navigation.findNavController(v);
                navController.navigate(action);
            }
        });

        return v;
    }
}